#ifndef   M_Code_FUNCTOR_H
#define   M_Code_FUNCTOR_H

class IFunctorBase {
  public:
    virtual ~IFunctorBase() {}
    virtual void* GetThis() = 0;
};

template<typename EventType> class IEventFunctorBase : public IFunctorBase {
  public:
    virtual void Call( EventType& event ) = 0;
};

template<class ClassType, typename EventType> class cbEventFunctor : public IEventFunctorBase<EventType> {
  private:
    typedef void ( ClassType::*Member )( EventType& );
    ClassType* m_pThis;
    Member m_pMember;
  public:
    cbEventFunctor( ClassType* this_, Member member ) : m_pThis( this_ ), m_pMember( member ) {}
    cbEventFunctor( const cbEventFunctor<ClassType, EventType>& rhs ) : m_pThis( rhs.m_pThis ), m_pMember( rhs.m_pMember ) {}
    virtual void* GetThis() { return m_pThis; }
    virtual void Call( EventType& event ) { if( m_pThis )( m_pThis->*m_pMember )( event ); }
};

#endif
